package ru.ifmo.croak.impl.replication.team1;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.ifmo.croak.impl.replication.team1.io.MulticastMessage;

public class Pinger implements Runnable {
    private static final Logger log = LoggerFactory.getLogger(ReplicationImplMain.class);
    private static final int PING_DELAY = 30000;
    Sender sender;

    public Pinger(Sender sender) {
        this.sender = sender;
    }

    public void run() {
        try {
            while (!Thread.interrupted()) {
                Thread.sleep(PING_DELAY);
                sender.sendSystemMessage(MulticastMessage.MessageType.PING);
            }
        } catch (InterruptedException e) {
            log.info("Thread was interrupted", e);
            Thread.currentThread().interrupt();
        }
    }

}
